<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>五子棋后端服务测试页面</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .container {
            background: white;
            border-radius: 20px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
            padding: 40px;
            max-width: 800px;
            width: 100%;
        }

        h1 {
            color: #333;
            margin-bottom: 10px;
            font-size: 28px;
        }

        .subtitle {
            color: #666;
            margin-bottom: 30px;
            font-size: 14px;
        }

        .test-section {
            margin-bottom: 30px;
        }

        .test-title {
            font-size: 18px;
            color: #444;
            margin-bottom: 15px;
            padding-bottom: 10px;
            border-bottom: 2px solid #667eea;
        }

        .button-group {
            display: flex;
            gap: 10px;
            margin-bottom: 15px;
        }

        button {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 12px 30px;
            border-radius: 8px;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
        }

        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
        }

        button:active {
            transform: translateY(0);
        }

        .response-box {
            background: #f5f5f5;
            border: 1px solid #ddd;
            border-radius: 8px;
            padding: 20px;
            margin-top: 15px;
            font-family: 'Consolas', 'Monaco', monospace;
            font-size: 14px;
            max-height: 300px;
            overflow-y: auto;
        }

        .response-box pre {
            margin: 0;
            white-space: pre-wrap;
            word-wrap: break-word;
        }

        .status {
            display: inline-block;
            padding: 5px 10px;
            border-radius: 4px;
            font-size: 12px;
            margin-bottom: 10px;
        }

        .status.success {
            background: #4caf50;
            color: white;
        }

        .status.error {
            background: #f44336;
            color: white;
        }

        .status.pending {
            background: #ff9800;
            color: white;
        }

        .info-box {
            background: #e3f2fd;
            border-left: 4px solid #2196f3;
            padding: 15px;
            margin-bottom: 20px;
            border-radius: 4px;
        }

        .info-box p {
            margin: 5px 0;
            color: #1976d2;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🎮 五子棋后端服务测试页面</h1>
        <p class="subtitle">用于测试后端服务是否正常运行</p>

        <div class="info-box">
            <p><strong>📌 服务地址：</strong>http://localhost:8080</p>
            <p><strong>💡 提示：</strong>请先启动后端服务，再点击下方按钮测试接口</p>
        </div>

        <!-- Hello World 测试 -->
        <div class="test-section">
            <div class="test-title">1️⃣ Hello World 接口测试</div>
            <div class="button-group">
                <button onclick="testHello()">测试 /hello 接口</button>
            </div>
            <div id="hello-response" class="response-box" style="display: none;">
                <div class="status pending">等待响应...</div>
                <pre id="hello-content"></pre>
            </div>
        </div>

        <!-- 健康检查测试 -->
        <div class="test-section">
            <div class="test-title">2️⃣ 健康检查接口测试</div>
            <div class="button-group">
                <button onclick="testHealth()">测试 /health 接口</button>
            </div>
            <div id="health-response" class="response-box" style="display: none;">
                <div class="status pending">等待响应...</div>
                <pre id="health-content"></pre>
            </div>
        </div>
    </div>

    <script>
        const API_BASE_URL = 'http://localhost:8080';

        async function testHello() {
            const responseBox = document.getElementById('hello-response');
            const contentBox = document.getElementById('hello-content');
            responseBox.style.display = 'block';
            
            try {
                const response = await fetch(`${API_BASE_URL}/hello`);
                const data = await response.json();
                
                responseBox.innerHTML = `
                    <div class="status success">✅ 请求成功 (${response.status})</div>
                    <pre>${JSON.stringify(data, null, 2)}</pre>
                `;
            } catch (error) {
                responseBox.innerHTML = `
                    <div class="status error">❌ 请求失败</div>
                    <pre>错误信息: ${error.message}\n\n请确认：\n1. 后端服务是否已启动\n2. 服务地址是否为 http://localhost:8080\n3. 是否存在跨域问题</pre>
                `;
            }
        }

        async function testHealth() {
            const responseBox = document.getElementById('health-response');
            const contentBox = document.getElementById('health-content');
            responseBox.style.display = 'block';
            
            try {
                const response = await fetch(`${API_BASE_URL}/health`);
                const data = await response.json();
                
                responseBox.innerHTML = `
                    <div class="status success">✅ 请求成功 (${response.status})</div>
                    <pre>${JSON.stringify(data, null, 2)}</pre>
                `;
            } catch (error) {
                responseBox.innerHTML = `
                    <div class="status error">❌ 请求失败</div>
                    <pre>错误信息: ${error.message}\n\n请确认：\n1. 后端服务是否已启动\n2. 服务地址是否为 http://localhost:8080\n3. 是否存在跨域问题</pre>
                `;
            }
        }

        // 页面加载时提示
        window.onload = function() {
            console.log('%c五子棋后端服务测试页面', 'color: #667eea; font-size: 20px; font-weight: bold;');
            console.log('%c测试接口：', 'color: #764ba2; font-size: 14px;');
            console.log('- GET /hello - Hello World 接口');
            console.log('- GET /health - 健康检查接口');
        };
    </script>
</body>
</html>

